﻿using System;
using System.Collections;
using System.Collections.Generic;
using SystemModule;

namespace M2Server
{
    public partial class TPlayObject
    {
        public void ProcessCommand(string sCmd, string sData)
        {
            string sParam1 = string.Empty;
            string sParam2 = string.Empty;
            string sParam3 = string.Empty;
            string sParam4 = string.Empty;
            string sParam5 = string.Empty;
            string sParam6 = string.Empty;
            string sParam7 = string.Empty;
            TPlayObject PlayObject;
            var SC = sData.Substring(1, sData.Length - 1);
            SC = HUtil32.GetValidStr3(SC, ref sCmd, new string[] { " ", ":", ",", "\09" });
            if (string.Compare((sCmd).ToLower(), (M2Share.g_GameCommand.SysMsg.sCmd).ToLower(), StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                CmdSysMsg(M2Share.g_GameCommand.SysMsg, SC); // 千里传音 
                return;
            }
            if (SC != "")
            {
                SC = HUtil32.GetValidStr3(SC, ref sParam1, new string[] { " ", ":", ",", "\09" });
            }
            if (SC != "")
            {
                SC = HUtil32.GetValidStr3(SC, ref sParam2, new string[] { " ", ":", ",", "\09" });
            }
            if (SC != "")
            {
                SC = HUtil32.GetValidStr3(SC, ref sParam3, new string[] { " ", ":", ",", "\09" });
            }
            if (SC != "")
            {
                SC = HUtil32.GetValidStr3(SC, ref sParam4, new string[] { " ", ":", ",", "\09" });
            }
            if (SC != "")
            {
                SC = HUtil32.GetValidStr3(SC, ref sParam5, new string[] { " ", ":", ",", "\09" });
            }
            if (SC != "")
            {
                SC = HUtil32.GetValidStr3(SC, ref sParam6, new string[] { " ", ":", ",", "\09" });
            }
            if (SC != "")
            {
                SC = HUtil32.GetValidStr3(SC, ref sParam7, new string[] { " ", ":", ",", "\09" });
            }

            if (string.Compare(sCmd.ToLower(), (M2Share.g_GameCommand.PASSWORDLOCK.sCmd).ToLower(), StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (!M2Share.g_Config.boPasswordLockSystem)
                {
                    SysMsg(GameMsgDef.g_sNoPasswordLockSystemMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                    return;
                }
                if (m_sStoragePwd == "")
                {
                    SendMsg(this, Grobal2.RM_PASSWORD, 0, 0, 0, 0, "");
                    m_boSetStoragePwd = true;
                    SysMsg(GameMsgDef.g_sSetPasswordMsg, TMsgColor.c_Green, TMsgType.t_Hint);
                    return;
                }
                if (m_btPwdFailCount > 3)
                {
                    SysMsg(GameMsgDef.g_sStoragePasswordLockedMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                    m_boPasswordLocked = true;
                    return;
                }
                if (m_sStoragePwd != "")
                {
                    SendMsg(this, Grobal2.RM_PASSWORD, 0, 0, 0, 0, "");
                    m_boCheckOldPwd = true;
                    SysMsg(GameMsgDef.g_sPleaseInputOldPasswordMsg, TMsgColor.c_Green, TMsgType.t_Hint);
                    return;
                }
                return;
            }
            // 新密码命令
            if (string.Compare((sCmd).ToLower(), (M2Share.g_GameCommand.SETPASSWORD.sCmd).ToLower(), StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (!M2Share.g_Config.boPasswordLockSystem)
                {
                    SysMsg(GameMsgDef.g_sNoPasswordLockSystemMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                    return;
                }
                if (m_sStoragePwd == "")
                {
                    SendMsg(this, Grobal2.RM_PASSWORD, 0, 0, 0, 0, "");
                    m_boSetStoragePwd = true;
                    SysMsg(GameMsgDef.g_sSetPasswordMsg, TMsgColor.c_Green, TMsgType.t_Hint);
                }
                else
                {
                    SysMsg(GameMsgDef.g_sAlreadySetPasswordMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                }
                return;
            }
            if (string.Compare(sCmd.ToLower(), (M2Share.g_GameCommand.UNPASSWORD.sCmd).ToLower(), StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (!M2Share.g_Config.boPasswordLockSystem)
                {
                    SysMsg(GameMsgDef.g_sNoPasswordLockSystemMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                    return;
                }
                if (!m_boPasswordLocked)
                {
                    m_sStoragePwd = "";
                    SysMsg(GameMsgDef.g_sOldPasswordIsClearMsg, TMsgColor.c_Green, TMsgType.t_Hint);
                }
                else
                {
                    SysMsg(GameMsgDef.g_sPleaseUnLockPasswordMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                }
                return;
            }
            if (string.Compare(sCmd.ToLower(), (M2Share.g_GameCommand.CHGPASSWORD.sCmd).ToLower(), StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (!M2Share.g_Config.boPasswordLockSystem)
                {
                    SysMsg(GameMsgDef.g_sNoPasswordLockSystemMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                    return;
                }
                if (m_btPwdFailCount > 3)
                {
                    SysMsg(GameMsgDef.g_sStoragePasswordLockedMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                    m_boPasswordLocked = true;
                    return;
                }
                if (m_sStoragePwd != "")
                {
                    SendMsg(this, Grobal2.RM_PASSWORD, 0, 0, 0, 0, "");
                    m_boCheckOldPwd = true;
                    SysMsg(GameMsgDef.g_sPleaseInputOldPasswordMsg, TMsgColor.c_Green, TMsgType.t_Hint);
                }
                else
                {
                    SysMsg(GameMsgDef.g_sNoPasswordSetMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                }
                return;
            }
            if (string.Compare((sCmd).ToLower(), (M2Share.g_GameCommand.UNLOCKSTORAGE.sCmd).ToLower(), StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                if (!M2Share.g_Config.boPasswordLockSystem)
                {
                    SysMsg(GameMsgDef.g_sNoPasswordLockSystemMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                    return;
                }
                if (m_btPwdFailCount > M2Share.g_Config.nPasswordErrorCountLock)
                {
                    SysMsg(GameMsgDef.g_sStoragePasswordLockedMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                    m_boPasswordLocked = true;
                    return;
                }
                if (m_sStoragePwd != "")
                {
                    if (!m_boUnLockStoragePwd)
                    {
                        SendMsg(this, Grobal2.RM_PASSWORD, 0, 0, 0, 0, "");
                        SysMsg(GameMsgDef.g_sPleaseInputUnLockPasswordMsg, TMsgColor.c_Green, TMsgType.t_Hint);
                        m_boUnLockStoragePwd = true;
                    }
                    else
                    {
                        SysMsg(GameMsgDef.g_sStorageAlreadyUnLockMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                    }
                }
                else
                {
                    SysMsg(GameMsgDef.g_sStorageNoPasswordMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                }
                return;
            }
            if (string.Compare((sCmd).ToLower(), (M2Share.g_GameCommand.UnLock.sCmd).ToLower(), StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                if (!M2Share.g_Config.boPasswordLockSystem)
                {
                    SysMsg(GameMsgDef.g_sNoPasswordLockSystemMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                    return;
                }
                if (m_btPwdFailCount > M2Share.g_Config.nPasswordErrorCountLock)
                {
                    SysMsg(GameMsgDef.g_sStoragePasswordLockedMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                    m_boPasswordLocked = true;
                    return;
                }
                if (m_sStoragePwd != "")
                {
                    if (!m_boUnLockPwd)
                    {
                        SendMsg(this, Grobal2.RM_PASSWORD, 0, 0, 0, 0, "");
                        SysMsg(GameMsgDef.g_sPleaseInputUnLockPasswordMsg, TMsgColor.c_Green, TMsgType.t_Hint);
                        m_boUnLockPwd = true;
                    }
                    else
                    {
                        SysMsg(GameMsgDef.g_sStorageAlreadyUnLockMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                    }
                }
                else
                {
                    SysMsg(GameMsgDef.g_sStorageNoPasswordMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                }
                return;
            }
            if (string.Compare((sCmd).ToLower(), (M2Share.g_GameCommand.__Lock.sCmd).ToLower(), StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                if (!M2Share.g_Config.boPasswordLockSystem)
                {
                    SysMsg(GameMsgDef.g_sNoPasswordLockSystemMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                    return;
                }
                if (!m_boPasswordLocked)
                {
                    if (m_sStoragePwd != "")
                    {
                        m_boPasswordLocked = true;
                        m_boCanGetBackItem = false;
                        SysMsg(GameMsgDef.g_sLockStorageSuccessMsg, TMsgColor.c_Green, TMsgType.t_Hint);
                    }
                    else
                    {
                        SysMsg(GameMsgDef.g_sStorageNoPasswordMsg, TMsgColor.c_Green, TMsgType.t_Hint);
                    }
                }
                else
                {
                    SysMsg(GameMsgDef.g_sStorageAlreadyLockMsg, TMsgColor.c_Red, TMsgType.t_Hint);
                }
                return;
            }
            if (PlayObjectUserCmd(sCmd, sParam1))// 自定义命令
            {
                return;
            }
            if (string.Compare(sCmd.ToLower(), (M2Share.g_GameCommand.MEMBERFUNCTIONEX.sCmd).ToLower(), StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                //CmdMemberFunctionEx(M2Share.g_GameCommand.MEMBERFUNCTIONEX.sCmd, sParam1);
                return;
            }
            if (string.Compare(sCmd.ToLower(), (M2Share.g_GameCommand.REMTEMSG.sCmd).ToLower(), StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                m_boRemoteMsg = true;
                SysMsg("允许接受消息。", TMsgColor.c_Green, TMsgType.t_Hint);
                return;
            }
            if (string.Compare(sCmd.ToLower(), (M2Share.g_GameCommand.MASTER.sCmd).ToLower(), StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                //CmdSearchMaster(M2Share.g_GameCommand.MASTER.sCmd, sParam1);
                return;
            }
            if (string.Compare(sCmd.ToLower(), (M2Share.g_GameCommand.ALLOWDEARRCALL.sCmd).ToLower(), StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                m_boCanDearRecall = !m_boCanDearRecall;
                if (m_boCanDearRecall)
                {
                    SysMsg(GameMsgDef.g_sEnableDearRecall, TMsgColor.c_Blue, TMsgType.t_Hint);// '允许夫妻传送！！！'
                }
                else
                {
                    SysMsg(GameMsgDef.g_sDisableDearRecall, TMsgColor.c_Blue, TMsgType.t_Hint);// '禁止夫妻传送！！！
                }
                return;
            }
            if (string.Compare(sCmd.ToLower(), (M2Share.g_GameCommand.ALLOWMASTERRECALL.sCmd).ToLower(), StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                m_boCanMasterRecall = !m_boCanMasterRecall;
                if (m_boCanMasterRecall)
                {
                    SysMsg(GameMsgDef.g_sEnableMasterRecall, TMsgColor.c_Blue, TMsgType.t_Hint);  // '允许师徒传送！！！'
                }
                else
                {
                    SysMsg(GameMsgDef.g_sDisableMasterRecall, TMsgColor.c_Blue, TMsgType.t_Hint);// '禁止师徒传送！！！'
                }
                return;
            }
            if (string.Compare((sCmd).ToLower(), (M2Share.g_GameCommand.Data.sCmd).ToLower(), StringComparison.CurrentCultureIgnoreCase) == 0)
            {
                // '当前日期时间: '
                //this.SysMsg(GameMsgDef.g_sNowCurrDateTime + FormatDateTime("dddddd,dddd,hh:mm:nn", DateTime.Now), TMsgColor.c_Blue, TMsgType.t_Hint);
                return;
            }
            if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.AllowReAlive.sCmd).ToLower()) == 0)
            {
                m_boAllowReAlive = !m_boAllowReAlive;
                if (m_boAllowReAlive)
                {
                    SysMsg(GameMsgDef.g_sEnableAllowRebirth, TMsgColor.c_Green, TMsgType.t_Hint);  // '[允许复活]'
                }
                else
                {
                    SysMsg(GameMsgDef.g_sDisableAllowRebirth, TMsgColor.c_Green, TMsgType.t_Hint);// '[禁止复活]'
                }
                return;
            }
            if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.SHOWEFFECT.sCmd).ToLower()) == 0)
            {
                //CmdShowEffect(M2Share.g_GameCommand.SHOWEFFECT, sParam1);
                return;
            }
            if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.ALLOWMSG.sCmd).ToLower()) == 0)
            {
                m_boHearWhisper = !m_boHearWhisper;
                if (m_boHearWhisper)
                {
                    SysMsg(GameMsgDef.g_sEnableHearWhisper, TMsgColor.c_Green, TMsgType.t_Hint); // '[允许私聊]'
                }
                else
                {
                    SysMsg(GameMsgDef.g_sDisableHearWhisper, TMsgColor.c_Green, TMsgType.t_Hint); // '[禁止私聊]'
                }
                return;
            }
            if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.LETSHOUT.sCmd).ToLower()) == 0)
            {
                m_boBanShout = !m_boBanShout;
                if (m_boBanShout)
                {
                    SysMsg(GameMsgDef.g_sEnableShoutMsg, TMsgColor.c_Green, TMsgType.t_Hint);// '[允许群聊]'
                }
                else
                {
                    SysMsg(GameMsgDef.g_sDisableShoutMsg, TMsgColor.c_Green, TMsgType.t_Hint);// '[禁止群聊]'
                }
                return;
            }
            if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.BANGMMSG.sCmd).ToLower()) == 0)
            {
                m_boBanGmMsg = !m_boBanGmMsg;// 拒绝所有喊话信息
                if (m_boBanGmMsg)
                {
                    SysMsg(GameMsgDef.g_sEnableBANGMMSG, TMsgColor.c_Green, TMsgType.t_Hint);// '[允许接收喊话]'
                }
                else
                {
                    SysMsg(GameMsgDef.g_sDisableBANGMMSG, TMsgColor.c_Green, TMsgType.t_Hint); // '[禁止接收喊话]'
                }
                return;
            }
            if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.LETTRADE.sCmd).ToLower()) == 0)
            {
                m_boAllowDeal = !m_boAllowDeal;
                if (m_boAllowDeal)
                {
                    SysMsg(GameMsgDef.g_sEnableDealMsg, TMsgColor.c_Green, TMsgType.t_Hint); // '[允许交易]'
                }
                else
                {
                    SysMsg(GameMsgDef.g_sDisableDealMsg, TMsgColor.c_Green, TMsgType.t_Hint);  // '[禁止交易]'
                }
                return;
            }
            if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.BANGUILDCHAT.sCmd).ToLower()) == 0)
            {
                m_boBanGuildChat = !m_boBanGuildChat;
                if (m_boBanGuildChat)
                {
                    SysMsg(GameMsgDef.g_sEnableGuildChat, TMsgColor.c_Green, TMsgType.t_Hint);// '[允许行会聊天]'
                }
                else
                {
                    SysMsg(GameMsgDef.g_sDisableGuildChat, TMsgColor.c_Green, TMsgType.t_Hint);// '[禁止行会聊天]'
                }
                return;
            }
            if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.LETGUILD.sCmd).ToLower()) == 0)
            {
                m_boAllowGuild = !m_boAllowGuild;
                if (m_boAllowGuild)
                {
                    SysMsg(GameMsgDef.g_sEnableJoinGuild, TMsgColor.c_Green, TMsgType.t_Hint); // '[允许加入行会]'
                }
                else
                {
                    SysMsg(GameMsgDef.g_sDisableJoinGuild, TMsgColor.c_Green, TMsgType.t_Hint); // '[禁止加入行会]'
                }
                return;
            }
            if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.AUTHALLY.sCmd).ToLower()) == 0)
            {
                if (IsGuildMaster())
                {
                    (m_MyGuild).m_boEnableAuthAlly = !(m_MyGuild).m_boEnableAuthAlly;
                    if ((m_MyGuild).m_boEnableAuthAlly)
                    {
                        SysMsg(GameMsgDef.g_sEnableAuthAllyGuild, TMsgColor.c_Green, TMsgType.t_Hint);// '[允许行会联盟]'
                    }
                    else
                    {
                        SysMsg(GameMsgDef.g_sDisableAuthAllyGuild, TMsgColor.c_Green, TMsgType.t_Hint);// '[禁止行会联盟]'
                    }
                }
                return;
            }
            if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.ALLOWGUILDRECALL.sCmd).ToLower()) == 0)
            {
                m_boAllowGuildReCall = !m_boAllowGuildReCall;
                if (m_boAllowGuildReCall)
                {
                    SysMsg(GameMsgDef.g_sEnableGuildRecall, TMsgColor.c_Green, TMsgType.t_Hint); // '[允许行会合一]'
                }
                else
                {
                    SysMsg(GameMsgDef.g_sDisableGuildRecall, TMsgColor.c_Green, TMsgType.t_Hint);  // '[禁止行会合一]'
                }
                return;
            }
            if (sCmd.ToLower().CompareTo((M2Share.g_GameCommand.AUTH.sCmd).ToLower()) == 0)
            {
                if (IsGuildMaster())
                {
                    ClientGuildAlly();
                }
                return;
            }
            if (sCmd.ToLower().CompareTo((M2Share.g_GameCommand.AUTHCANCEL.sCmd).ToLower()) == 0)
            {
                if (IsGuildMaster())
                {
                    ClientGuildBreakAlly(sParam1);
                }
                return;
            }
            if (sCmd.ToLower().CompareTo((M2Share.g_GameCommand.MAPINFO.sCmd).ToLower()) == 0)
            {
                ShowMapInfo(sParam1, sParam2, sParam3);
                return;
            }
            if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.LOCKLOGON.sCmd).ToLower()) == 0)
            {
                //CmdLockLogin(M2Share.g_GameCommand.LOCKLOGON);
                return;
            }
            if ((m_btPermission >= 2) && (sData.Length > 2))
            {
                if ((m_btPermission >= 6) && (sData[2] == M2Share.g_GMRedMsgCmd))
                {
                    if (HUtil32.GetTickCount() - m_dwSayMsgTick > 2000)
                    {
                        m_dwSayMsgTick = HUtil32.GetTickCount();
                        sData = sData.Substring(3 - 1, sData.Length - 2);
                        if (sData.Length > M2Share.g_Config.nSayRedMsgMaxLen)
                        {
                            sData = sData.Substring(1 - 1, M2Share.g_Config.nSayRedMsgMaxLen);
                        }
                        if (M2Share.g_Config.boShutRedMsgShowGMName)
                        {
                            SC = m_sCharName + ": " + sData;
                        }
                        else
                        {
                            SC = sData;
                        }
                        M2Share.UserEngine.SendBroadCastMsg(SC, TMsgType.t_GM);
                    }
                    return;
                }
            }
            if (m_btPermission > 4)
            {
                if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.SETFLAG.sCmd).ToLower()) == 0)
                {
                    PlayObject = M2Share.UserEngine.GetPlayObject(sParam1);
                    if (PlayObject != null)
                    {
                        int nFlag = HUtil32.Str_ToInt(sParam2, 0);
                        int nValue = HUtil32.Str_ToInt(sParam3, 0);
                        PlayObject.SetQuestFlagStatus(nFlag, nValue);
                        if (PlayObject.GetQuestFalgStatus(nFlag) == 1)
                        {
                            SysMsg(PlayObject.m_sCharName + ": [" + (nFlag).ToString() + "] = ON", TMsgColor.c_Green, TMsgType.t_Hint);
                        }
                        else
                        {
                            SysMsg(PlayObject.m_sCharName + ": [" + (nFlag).ToString() + "] = OFF", TMsgColor.c_Green, TMsgType.t_Hint);
                        }
                    }
                    else
                    {
                        SysMsg("@" + M2Share.g_GameCommand.SETFLAG.sCmd + " 人物名称 标志号 数字(0 - 1)", TMsgColor.c_Red, TMsgType.t_Hint);
                    }
                    return;
                }
                if ((m_btPermission >= 5) || (M2Share.g_Config.boTestServer))
                {
                    if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.RELOADITEMDB.sCmd).ToLower()) == 0)
                    {
                        LocalDB.GetInstance().LoadItemsDB();
                        SysMsg("物品数据库重新加载完成。", TMsgColor.c_Green, TMsgType.t_Hint);
                        return;
                    }
                    if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.RELOADMAGICDB.sCmd).ToLower()) == 0)
                    {
                        LocalDB.GetInstance().LoadMagicDB();
                        SysMsg("魔法数据库重新加载完成。", TMsgColor.c_Green, TMsgType.t_Hint);
                        return;
                    }
                    if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.RELOADMONSTERDB.sCmd).ToLower()) == 0)
                    {
                        LocalDB.GetInstance().LoadMonsterDB();
                        SysMsg("怪物数据库重新加载完成。", TMsgColor.c_Green, TMsgType.t_Hint);
                        return;
                    }
                    if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.RELOADMINMAP.sCmd).ToLower()) == 0)
                    {
                        LocalDB.GetInstance().LoadMinMap();
                        M2Share.g_MapManager.ReSetMinMap();
                        SysMsg("小地图配置重新加载完成。", TMsgColor.c_Green, TMsgType.t_Hint);
                        return;
                    }
                    if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.NGLEVEL.sCmd).ToLower()) == 0)
                    {
                        CmdNGLevel(M2Share.g_GameCommand.NGLEVEL, sParam1, HUtil32.Str_ToInt(sParam2, 1));  // 调整内功等级
                        return;
                    }
                    else if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.TESTSERVERCONFIG.sCmd).ToLower()) == 0)
                    {
                        SendServerConfig();
                        return;
                    }
                    else if ((sCmd).ToLower().CompareTo((M2Share.g_GameCommand.SERVERSTATUS.sCmd).ToLower()) == 0)
                    {
                        SendServerStatus();
                        return;
                    }
                    else
                    {
                        M2Share.CommandSystem.ExecCmd(sData, this);
                    }
                }
            }
            if (M2Share.g_Config.boGMShowFailMsg)
            {
                SysMsg("@" + sCmd + " 此命令不正确，或没有足够的权限！！！", TMsgColor.c_Red, TMsgType.t_Hint);// GM命令错误是否提示
            }
        }

        // 英雄的忠诚度
        public void CmdHeroLoyal(TGameCmd Cmd, string sHumanName, int nHeroLoyal)
        {
            TBaseObject PlayObject;
            if ((m_btPermission < Cmd.nPermissionMin))
            {
                SysMsg(GameMsgDef.g_sGameCommandPermissionTooLow, TMsgColor.c_Red, TMsgType.t_Hint);// 权限不够
                return;
            }
            if ((sHumanName == "") || (nHeroLoyal < 0) || (nHeroLoyal > 10000) || ((sHumanName != "") && (sHumanName[0] == '?')))
            {
                if (M2Share.g_Config.boGMShowFailMsg)
                {
                    SysMsg(string.Format(GameMsgDef.g_sGameCommandParamUnKnow, Cmd.sCmd, GameMsgDef.g_sGameCommandHeroLoyalHelpMsg), TMsgColor.c_Red, TMsgType.t_Hint);
                }
                return;
            }
            PlayObject = M2Share.UserEngine.GetHeroObject(sHumanName);
            if (PlayObject != null)
            {
                ((THeroObject)(PlayObject)).m_nLoyal = nHeroLoyal;
                m_DefMsg = EncryptUnit.MakeDefaultMsg(Grobal2.SM_HEROABILITY, ((THeroObject)(PlayObject)).m_btGender, 0, ((THeroObject)(PlayObject)).m_btJob, ((THeroObject)(PlayObject)).m_nLoyal, 0);
                //替换上面一句
                //SendSocket(this.m_DefMsg, EncryptUnit.EncodeBuffer(((THeroObject)(PlayObject)).m_WAbil, sizeof(TAbility)));
                SysMsg("[英雄忠诚度调整] " + sHumanName + " -> (" + (((THeroObject)(PlayObject)).m_nLoyal / 100).ToString() + "%)", TMsgColor.BB_Fuchsia, TMsgType.t_Hint);
                if (M2Share.g_Config.boShowMakeItemMsg)
                {
                    M2Share.MainOutMessage("[英雄忠诚度调整] " + sHumanName + " -> (" + (((THeroObject)(PlayObject)).m_nLoyal).ToString() + ")");
                }
            }
            else
            {
                SysMsg("英雄" + sHumanName + "现在不在线。", TMsgColor.c_Red, TMsgType.t_Hint);
            }
        }

        // 千里传音
        private void CmdSysMsg(TGameCmd Cmd, string Text)
        {
            TStdItem AmuletStdItem;
            TPlayObject PlayObject;
            if (Text == "")
            {
                SysMsg("命令格式: @" + Cmd.sCmd + " 发布信息", TMsgColor.c_Red, TMsgType.t_Hint);
                return;
            }
            M2Share.IsFilterMsg(ref Text);// 文字过滤
            if (m_UseItems[Grobal2.U_CHARM]!=null&&m_UseItems[Grobal2.U_CHARM].wIndex > 0)
            {
                AmuletStdItem = M2Share.UserEngine.GetStdItem(m_UseItems[Grobal2.U_CHARM].wIndex);
                if ((AmuletStdItem != null) && (AmuletStdItem.StdMode == 7) && (AmuletStdItem.Shape == 0)) // 物品是千里传音
                {
                    if (m_UseItems[Grobal2.U_CHARM].Dura >= 1000)
                    {
                        m_UseItems[Grobal2.U_CHARM].Dura -= 1000;
                        SendMsg(this, Grobal2.RM_DURACHANGE, Grobal2.U_CHARM, m_UseItems[Grobal2.U_CHARM].Dura, m_UseItems[Grobal2.U_CHARM].DuraMax, 0, "");// 减少持久数
                        try
                        {
                            //千里传音 的字的颜色
                            HUtil32.EnterCriticalSection(M2Share.ProcessHumanCriticalSection);
                            for (int i = 0; i < M2Share.UserEngine.m_PlayObjectList.Count; i++)
                            {
                                PlayObject = M2Share.UserEngine.m_PlayObjectList[i];
                                if (PlayObject != null)
                                {
                                    if (!PlayObject.m_boGhost)
                                    {
                                        PlayObject.SysMsg(m_sCharName + ":" + Text, TMsgColor.c_Fuchsia, TMsgType.t_Say);
                                    }
                                }
                            }
                        }
                        finally
                        {
                            HUtil32.LeaveCriticalSection(M2Share.ProcessHumanCriticalSection);
                        }
                        if (m_UseItems[Grobal2.U_CHARM].Dura <= 0)
                        {
                            SendDelItems(m_UseItems[Grobal2.U_CHARM]);// 如果使用完，则删除物品
                            m_UseItems[Grobal2.U_CHARM].Dura = 0;
                            m_UseItems[Grobal2.U_CHARM].wIndex = 0;
                        }
                    }
                    else
                    {
                        SendDelItems(m_UseItems[Grobal2.U_CHARM]); // 如果使用完，则删除物品
                        m_UseItems[Grobal2.U_CHARM].Dura = 0;
                        m_UseItems[Grobal2.U_CHARM].wIndex = 0;
                    }
                }
            }
            else
            {
                SysMsg("没有千里传音,或没有穿上装备栏里。", TMsgColor.c_Red, TMsgType.t_Hint);
            }
        }

        // 调整人物内功等级
        public void CmdNGLevel(TGameCmd Cmd, string sHumanName, int nLevel)
        {
            TPlayObject PlayObject;
            TBaseObject HeroObject;
            int nOLevel;
            if ((m_btPermission < Cmd.nPermissionMin))
            {
                SysMsg(GameMsgDef.g_sGameCommandPermissionTooLow, TMsgColor.c_Red, TMsgType.t_Hint);
                return;
            }
            if ((sHumanName == "") || (nLevel < 0) || (nLevel > 255))
            {
                if (M2Share.g_Config.boGMShowFailMsg)
                {
                    SysMsg("命令格式: @" + Cmd.sCmd + " 人物名称 内功等级(1-255)", TMsgColor.c_Red, TMsgType.t_Hint);
                }
                return;
            }
            PlayObject = M2Share.UserEngine.GetPlayObject(sHumanName);
            if (PlayObject != null)
            {
                if (PlayObject.m_boTrainingNG)
                {
                    nOLevel = PlayObject.m_NGLevel;
                    PlayObject.m_NGLevel = (byte)HUtil32._MAX(1, HUtil32._MIN(255, nLevel));
                    PlayObject.SendNGData();// 发送内功数据
                    PlayObject.SendRefMsg(Grobal2.RM_MYSHOW, Grobal2.ET_OBJECTLEVELUP, 0, 0, 0, "");// 人物升级动画 
                    NGLevelUpFunc();// 内功升级触发
                    // 等级调整记录日志
                    M2Share.AddGameDataLog("17" + "\09" + PlayObject.m_sMapName + "\09" + (PlayObject.m_nCurrX).ToString() + "\09" +
                        (PlayObject.m_nCurrY).ToString() + "\09" + PlayObject.m_sCharName + "\09" + (PlayObject.m_NGLevel).ToString() + "\09" + "内功" + "\09" + "=("
                        + (nLevel).ToString() + ")" + "\09" + m_sCharName + "(GM)");
                    SysMsg(sHumanName + " 内功等级调整完成。", TMsgColor.c_Green, TMsgType.t_Hint);
                    if (M2Share.g_Config.boShowMakeItemMsg)
                    {
                        M2Share.MainOutMessage("[内功等级调整] " + m_sCharName + "(" + PlayObject.m_sCharName + " " + (nOLevel).ToString() + " -> " +
                            (PlayObject.m_NGLevel).ToString() + ")");
                    }
                }
                else
                {
                    SysMsg(PlayObject.m_sCharName + " 还未学习内功心法!!!", TMsgColor.c_Red, TMsgType.t_Hint);
                }
            }
            else
            {
                HeroObject = M2Share.UserEngine.GetHeroObject(sHumanName);// 查找英雄
                if (HeroObject != null)
                {
                    if (((THeroObject)(HeroObject)).m_boTrainingNG)
                    {
                        nOLevel = ((THeroObject)(HeroObject)).m_NGLevel;
                        ((THeroObject)(HeroObject)).m_NGLevel = (byte)HUtil32._MAX(1, HUtil32._MIN(255, nLevel));
                        HeroObject.SendNGData();// 发送内功数据
                        HeroObject.SendRefMsg(Grobal2.RM_MYSHOW, Grobal2.ET_OBJECTLEVELUP, 0, 0, 0, "");// 人物升级动画 
                        ((THeroObject)(HeroObject)).NGLevelUpFunc();// 内功升级触发
                        // 等级调整记录日志
                        M2Share.AddGameDataLog("17" + "\09" + HeroObject.m_sMapName + "\09" + (HeroObject.m_nCurrX).ToString() + "\09" + (HeroObject.m_nCurrY).ToString()
                            + "\09" + HeroObject.m_sCharName + "\09" + (((THeroObject)(HeroObject)).m_NGLevel).ToString() + "\09" + "英雄内功" + "\09" + "=(" + (nLevel).ToString() + ")"
                            + "\09" + m_sCharName + "(GM)");
                        SysMsg(sHumanName + " 内功等级调整完成。", TMsgColor.c_Green, TMsgType.t_Hint);
                        if (M2Share.g_Config.boShowMakeItemMsg)
                        {
                            M2Share.MainOutMessage("[内功等级调整] " + m_sCharName + "(" + HeroObject.m_sCharName + " " + (nOLevel).ToString() + " -> "
                                + (((THeroObject)(HeroObject)).m_NGLevel).ToString() + ")");
                        }
                    }
                    else
                    {
                        SysMsg(HeroObject.m_sCharName + " 还未学习内功心法!!!", TMsgColor.c_Red, TMsgType.t_Hint);
                    }
                }
                else
                {
                    SysMsg(string.Format(GameMsgDef.g_sNowNotOnLineOrOnOtherServer, new string[] { sHumanName }), TMsgColor.c_Red, TMsgType.t_Hint);
                }
            }
        }

        /// <summary>
        /// 自定义命令
        /// </summary>
        /// <returns></returns>
        public bool PlayObjectUserCmd(string sLable, string sParam)
        {
            bool result = false;
            int nCode = 0;
            try
            {
                if ((M2Share.g_UserCmdList == null) || (M2Share.g_UserCmdList.Count <= 0))
                {
                    return result;
                }
                if (!M2Share.g_UserCmdList.TryGetValue(sLable.ToLower(), out nCode))
                {
                    return result;
                }
                m_nScriptGotoCount = 0;//初始化跳转次数
                sLable = "@UserCmd" + nCode;
                if ((nCode > 99) || (nCode < 0))
                {
                    nCode = 0;
                }
                m_sString[nCode] = sParam;
                m_nInteger[nCode] = HUtil32.Str_ToInt(sParam, 0);
                M2Share.CommandSystem.ExecCmd("@UserCmd " + sLable, this);// 执行QF触发
                result = true;
            }
            catch
            {
                M2Share.MainOutMessage("[异常] TPlayObject.PlayObjectUserCmd");
            }
            return result;
        }
    }
}